package com.sport.setting.controller;

import com.sport.apis.annotation.SportStatus;
import com.sport.model.common.dtos.ResponseResult;
import com.sport.model.common.enums.AppHttpCodeEnum;
import com.sport.model.program.dtos.AllocatedGroupDto;
import com.sport.model.program.dtos.AllocatedItemDto;
import com.sport.setting.service.SportProgramService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

@Slf4j
@RestController
@RequestMapping("/SportProgram")
@SportStatus(sportTargetStatus = SportStatus.InnerStatus.ORGANIZE_SPORT_MEETING)
public class SportProgramController {
    @Autowired
    SportProgramService sportProgramService;


    /**
     * 未分配的项目
     * @return
     */
    @GetMapping("/unallocatedItem")
    public ResponseResult unallocatedItem(){
        return ResponseResult.okResult(sportProgramService.unallocatedItem());
    }

    /**
     * 已经分配的项目
     * @param allocatedGroupDto
     * @return
     */
    @PostMapping("/allocatedItem")
    public ResponseResult allocatedItem(@RequestBody AllocatedGroupDto allocatedGroupDto){
        return ResponseResult.okResult(sportProgramService.allocatedItem(allocatedGroupDto));
    }

    /**
     * 更新分配的项目
     * @param allocatedItemDto
     * @return
     */
    @PostMapping("/updateAllocatedItem")
    public ResponseResult updateAllocatedItem(@RequestBody @Validated AllocatedItemDto allocatedItemDto){
        return sportProgramService.updateAllocatedItem(allocatedItemDto);
    }


    /**
     * 导出秩序册
     */
    @GetMapping("/exportProgram")
    public void exportProgram(HttpServletResponse response){
          sportProgramService.exportProgram(response);
    }


    /**
     * word秩序册
     */
    @GetMapping("/exportWordProgram")
    public void exportWordProgram(HttpServletResponse response){
        sportProgramService.exportWordProgram(response,"运动会秩序册.docx");
    }

}
